<?php
class Album extends Model {
	public function addAlbum($name,$desc) {
		return $this->dbo->query("INSERT INTO album (name,description) VALUES ('".$this->dbo->escape($name)."','".$this->dbo->escape($desc)."')");
	}
	public function getAlbumList() {
		$result = $this->dbo->query("SELECT * FROM album");
		return $result->rows;
	}
	public function getAlbumById($album_id) {
		$result = $this->dbo->query("SELECT * FROM album WHERE id= '".(int)$album_id."'");
		return $result->row;
	}
	public function editAlbum($album_id,$name,$desc) {
		return $this->dbo->query("UPDATE album SET name='".$this->dbo->escape($name)."',description = '".$this->dbo->escape($desc)."' WHERE id = '".(int)$album_id."'");
	}
	public function updateAlbumImage($album_id,$img) {
		return $this->dbo->query("UPDATE album SET image='".$this->dbo->escape($img)."' WHERE id = '".(int)$album_id."'");
	}
	public function getPhotoListByAlbumId($album_id) {
		$result = $this->dbo->query("SELECT * FROM photo WHERE album_id='".(int)$album_id."'");
		return $result->rows;
	}
	public function addPhoto($album_id,$name,$description,$image,$thumbnail,$url) {
		return $this->dbo->query("INSERT INTO photo (album_id,name,description,image,thumbnail,url,created) VALUES ('".(int)$album_id."','".$this->dbo->escape($name)."','".$this->dbo->escape($description)."','".$this->dbo->escape($image)."','".$this->dbo->escape($thumbnail)."','".$this->dbo->escape($url)."','".date('Y-m-d H:i:s')."')");
	}
	public function getPhotoByIds($photo_ids) {
		$result = $this->dbo->query("SELECT * FROM photo WHERE id IN ($photo_ids)");
		return $result->rows;
	}
	public function delPhotoByIds($photo_ids) {
		return $this->dbo->query("DELETE FROM photo WHERE id IN ($photo_ids)");
	}
	public function delAlbumByid($album_id) {
		return $this->dbo->query("DELETE FROM album WHERE id IN ($album_id)");
	}
	public function updatePhotoInfo($photo_id,$image,$thumbnail,$url) {
		return $this->dbo->query("UPDATE photo SET image='".$this->dbo->escape($image)."',thumbnail='".$this->dbo->escape($thumbnail)."' ,url='".$this->dbo->escape($url)."' WHERE id='".(int)$photo_id."'");
	}
}
?>